package com.example.bookkeepingelf.business.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.bookkeepingelf.R;
import com.example.bookkeepingelf.base.utils.DateUtils;
import com.example.bookkeepingelf.business.bean.BillFlowDayVo;

import java.util.ArrayList;
import java.util.List;

public class HomeBillDayRecyclerViewAdapter extends RecyclerView.Adapter<HomeBillDayRecyclerViewAdapter.HomeBillDayViewHolder> {

    private Context context;

    private LayoutInflater layoutInflater;
    private List<BillFlowDayVo> billFlowDayVos;


    public HomeBillDayRecyclerViewAdapter(Context context, List<BillFlowDayVo> billFlowDayVos) {
        this.context = context;
        this.billFlowDayVos = billFlowDayVos;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public HomeBillDayRecyclerViewAdapter.HomeBillDayViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view = layoutInflater.inflate(R.layout.fragment_bill_flow_item, parent, false);
        return new HomeBillDayRecyclerViewAdapter.HomeBillDayViewHolder(view, this);
    }

    @Override
    public void onBindViewHolder(@NonNull HomeBillDayViewHolder holder, int position) {
        BillFlowDayVo billFlowDayVo = this.billFlowDayVos.get(position);
        TextView bfiDateTextView = holder.bfiDateTextView;
        TextView bfiWeekTextView = holder.bfiWeekTextView;
        TextView bfiIncomeTextView = holder.bfiIncomeTextView;
        TextView bfiExpensesTextView = holder.bfiExpensesTextView;
        bfiDateTextView.setText(DateUtils.dateToString(billFlowDayVo.getCreateDate(), DateUtils.DATE_TEMPLATE_1));
        bfiWeekTextView.setText("星期四");
        bfiIncomeTextView.setText(billFlowDayVo.getIncomeAmount().toString());
        bfiExpensesTextView.setText(billFlowDayVo.getExpensesAmount().toString());


        RecyclerView innerRecyclerView = holder.innerRecyclerView;
        // 假设有一个名为 iconNames 的字符串数组包含了所有的图标名称
        HomeBillItemRecyclerViewInnerAdapter innerAdapter = new HomeBillItemRecyclerViewInnerAdapter(context, billFlowDayVo.getBillFlows()); // 传递实际的数据源
        innerRecyclerView.setAdapter(innerAdapter);
        // 设置网格布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        innerRecyclerView.setLayoutManager(linearLayoutManager);
    }

    @Override
    public int getItemCount() {
        return billFlowDayVos.size();
    }

    public static class HomeBillDayViewHolder extends RecyclerView.ViewHolder {

        TextView bfiDateTextView;

        TextView bfiWeekTextView;

        TextView bfiIncomeTextView;

        TextView bfiExpensesTextView;

        RecyclerView innerRecyclerView;

        public HomeBillDayViewHolder(@NonNull View itemView, HomeBillDayRecyclerViewAdapter homeBillDayRecyclerViewAdapter) {
            super(itemView);
            this.bfiDateTextView = itemView.findViewById(R.id.bfi_date_text_view);
            this.bfiWeekTextView = itemView.findViewById(R.id.bfi_week_text_view);
            this.bfiIncomeTextView = itemView.findViewById(R.id.bfi_income_text_view);
            this.bfiExpensesTextView = itemView.findViewById(R.id.bfi_expenses_text_view);
            this.innerRecyclerView = itemView.findViewById(R.id.bill_item_list);
        }



    }

}
